﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class OutPutMaterialManage
{
    private List<Vector3> gFinishMaterialPositionList;
    private List<bool> gFinishMaterailBool;
    private List<GameObject> gGameObjectList;

    public OutPutMaterialManage ()
    {
        InitPositionList();
    }

    public void AddFinishMaterial(GameObject iFinishMaterial)
    {
        //1、判断第几个位置是空闲的
        int pIndex = -1;
        for(int i=0;i<gFinishMaterailBool .Count;i++)
        {
            if(gFinishMaterailBool [i]==false )
            {
                pIndex = i;
                break;
            }
        }
        //如果，都不为空，则表明摆满，则重新清空
        if(pIndex ==-1)
        {
            while (gGameObjectList.Count !=0)
            {
                GameObject pGameObject = gGameObjectList[0];
                gGameObjectList.RemoveAt(0);
                GameObject.Destroy(pGameObject);
            }
            for(int i=0;i<gFinishMaterailBool .Count;i++)
            {
                gFinishMaterailBool[i] = false;
            }
            pIndex = 0;
        }
        iFinishMaterial.transform.parent = null;
        gGameObjectList.Add(iFinishMaterial);
        iFinishMaterial.transform.position = gFinishMaterialPositionList[pIndex];
        gFinishMaterailBool[pIndex] = true;
    }

    private void InitPositionList()
    {
        gFinishMaterialPositionList = new List<Vector3>();
        gFinishMaterailBool = new List<bool>();
        gGameObjectList = new List<GameObject>();

        int pX = 350, pY = 35, pZ = -200;
        for (int i=0;i<5;i++)
        {
            for(int j=0;j<5;j++)
            {
                pX = 350 + 20 * i;
                pZ = -200 - 20 * j;

                gFinishMaterialPositionList.Add(new Vector3(pX, pY, pZ));
                gFinishMaterailBool.Add(false);
            }
        }

    }

}
